Skip to content

Fix grid property amplification, Apple alpha, narrow grids and AV1 header strictness - #17

Closed
laurens-pilot wants to merge 5 commits into
mainfrom
fix/review-findings
Closed

laurens-pilot wants to merge 5 commits into
mainfrom
fix/review-findings

Conversation

@laurens-pilot

Copy link
Copy Markdown
Owner

Fixes for five problems found while reviewing last week's changes (ente#13 through ente#26), one commit each:

  • Grid tile properties are shared instead of copied per reference. Every grid reference used to clone its tile's hvcC, colour properties and transforms. A 68 KB file whose 32×32 grid points every cell at one tile peaked at 2.4 GB, and a 1.6 MB one with tiny hvcC NAL units at 5.4 GB; both now stay under 30 MB. Grids that attach one large ICC profile to every tile, as ImageIO writes them, keep decoding. HeicGridTileItemData's hvcc, colr and transforms are now Arcs.
  • Monochrome HEVC no longer reads intra_chroma_pred_mode. Reading it desynchronised CABAC in 4:0:0 streams, so Apple's alpha planes decoded to wrong values.
  • Auxiliary alpha may be coded beyond the primary's CTB padding. ImageIO codes small images at 160×64 and crops them, so their alpha was being dropped.
  • Narrow 1×N / N×1 grids size their byte budget from the 512 px tile span, so ImageIO images such as 40×30000 decode again.
  • The AV1 geometry preflight ignores the OBU forbidden and reserved bits, as rav1d does.

Checked against a 283-file sweep (libheif and ente fixture corpora plus sips-generated HEIC/AVIF): only the files these fixes target changed output; ImageIO alpha now matches ImageIO's own decode. The libheif verify corpus job was not run locally.

Grid-shaped alpha (e.g. 4000×3000 Apple images) is still unsupported, as before.

A grid can reference the same tile item many times, and many tile
items can share one ipco property. Every reference cloned its tile's
hvcC NAL units, ICC profile and transform list, and only tile payloads
counted against the tile data budget. A 68 KB file whose 32x32 grid
points every cell at one tile carrying about 65,000 irot associations
peaked at 2.4 GB before any decoding started, and a tile hvcC holding
hundreds of thousands of one-byte NAL units multiplies the same way.

HeicGridTileItemData now holds its hvcC, colour properties and
transforms behind Arc. Each hvcC property is parsed once and shared by
every tile that uses it, colour properties are shared per nclx and ICC
combination, and each distinct tile item resolves its transforms once,
so a repeated reference costs a handle instead of a copy. ICC bytes
copied into each new colour combination still count against the tile
data budget, so one large profile cannot be multiplied through many
distinct combinations. Grids that attach one large ICC profile to
every tile, as ImageIO writes them, keep decoding.

This changes the field types of the public HeicGridTileItemData.
intra_chroma_pred_mode is only coded when ChromaArrayType is not 0
(H.265 7.3.8.5), but the CTU decoder read it for every intra coding
unit. In 4:0:0 streams that consumed bins belonging to the next syntax
element and desynchronised CABAC without an error. Apple stores alpha
as 4:0:0 Range Extensions streams, so transparent HEICs from ImageIO
decoded with garbage alpha.

Return the luma mode without reading anything when there is no chroma.
A 192x64 ImageIO fixture now decodes to within 2 of its source alpha
ramp, the same tolerance ImageIO's own decode has.
ImageIO codes HEVC frames at no less than 160x64 and crops them with
the conformance window, so the alpha plane of a 40x30 image is a
160x64 frame. Preflight rejected auxiliary frames whose coded size
went past the primary's visible size rounded up to a CTB, and such
images decoded without their transparency.

Drop that bound. The alpha's visible geometry must still match the
primary, and its coded frame still counts against max_pixels and the
decoded-byte allowance of the primary area, so cropping cannot hide an
oversized frame.
ImageIO stores images narrower than its 512x512 tiles as 1xN or Nx1
grids of full tiles. ente#22 lets a single-span tile reach
512 px on such grids, but the decoded-byte allowance still came from
the visible output area, which the tiles' decoded planes far exceed.
ImageIO files at 40x30000, 60x30000, 100x40000 and 30000x40 all failed
preflight.

Count a dimension covered by one tile row or column as at least 512 px
when tiles are stacked along the other dimension, matching the tile
extent rule. max_pixels still caps the allowance.
The preflight rejected OBUs with the forbidden or reserved header bit
set. rav1d ignores both unless strict standard compliance is enabled,
which this decoder never does, so the preflight failed files the
decoder itself accepts. Parse OBU headers the way the decoder does.
@laurens-pilot

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T04:54:30.005409Z 11ec338 Manual request
🔒 Security Review ✅ Completed 2026-11-03T04:56:40.273303Z 11ec338 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 11ec338a36

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 11ec338a36

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@laurens-pilot

Copy link
Copy Markdown
Owner Author

Superseded by ente#29.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants